//
//  HMWelcomeViewController.m
//  HMWeiBoOC
//
//  Created by GD on 16/9/22.
//  Copyright © 2016年 geduo. All rights reserved.
//

#import "HMWelcomeViewController.h"
#import <Masonry.h>
#import "HMUserAccountViewModel.h"
#import "HMUserAccount.h"
#import <UIImageView+WebCache.h>
#import "HMGlobalConst.h"


@interface HMWelcomeViewController ()
    @property (weak, nonatomic) IBOutlet NSLayoutConstraint *iconTopConstraint;
    @property (weak, nonatomic) IBOutlet UIImageView *iconView;
    
    @property (weak, nonatomic) IBOutlet UILabel *welcomeLabel;
    

@end

@implementation HMWelcomeViewController
    
-(void)awakeFromNib{
    self.iconView.layer.cornerRadius = 85/2;
    self.iconView.clipsToBounds = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.welcomeLabel.alpha = 0;
    
    if ([[HMUserAccountViewModel sharedViewModel].userAccount name]) {
        self.welcomeLabel.text = [NSString stringWithFormat:@"欢迎回来%@",[[HMUserAccountViewModel sharedViewModel].userAccount name]];
    }
    
    NSString *imageURL = [HMUserAccountViewModel sharedViewModel].userAccount.profile_image_url;
    if (imageURL) {
        [self.iconView sd_setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:nil ];
    }
}
    
    
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self startAnimating];
}

- (void)startAnimating {
//    [self.iconView mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.
//    }];
    self.iconTopConstraint.constant = 100;
    
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:0 options:0 animations:^{
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        
        
        [UIView animateWithDuration:1.0 animations:^{
            self.welcomeLabel.alpha = 1;
        } completion:^(BOOL finished) {
            //通过通知的方式 切换到首页
            NSLog(@"通知 到 首页");
            [[NSNotificationCenter defaultCenter] postNotificationName:SwitchRootVCNotification object:nil];
        }];
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
